package com.itheima.d3_exception.Case;

/**
 * @ClassName Case1
 * @Author 16799
 * @Date 2025/7/23 9:47
 * @Version 1.0
 * @Description TODO
 **/
public class Case1 {
    public static void main(String[] args) {

        //getSex("abc");

        //getSex1("dd");
        try {
            getSex1("df");
            System.out.println("输入男女性别成功");
        }catch (SexIllegalException e){
            e.printStackTrace();
        }

        try {
            getSex("safs");
            System.out.println("输入男女性别成功");
        } catch (Exception e) {
            System.out.println("我是第二次的运行时异常");
            //e.printStackTrace();
            throw new RuntimeException(e);  //这还会往上抛，到SexIllegalRuntimeException这里去
        }

    }

    private static void getSex(String sex){
        if (sex.equals("男")||sex.equals("女")){
            System.out.println("输入性别正确");
        }else {
            throw new SexIllegalRuntimeException("运行时异常，给你爹输男女");
        }
    }

    private static void getSex1(String sex) throws SexIllegalException {
        if (sex.equals("男")||sex.equals("女")){
            System.out.println("输入性别正确");
        }else {
            throw new SexIllegalException("我是编译时异常，给你爹输男女");
        }
    }

}
